package com.czkt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.czkt.entity.CstLost;
import com.czkt.service.ICstLostService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2024-06-18
 */
@Controller
public class CstLostController {
    @Resource
    ICstLostService cstLostService;

    /**
     * 客户流失管理
     * @param lstCustName 客户姓名
     * @param lstCustManagerName 客户经理姓名
     * @param pageIndex 当前页数
     * @param pageSize 每页记录数
     * @param model 传值
     * @return 跳转到客户流失列表
     */
    @RequestMapping("/lost/list")
    public String cstLostShow(@RequestParam(value = "lstCustName",defaultValue = "") String lstCustName,
                              @RequestParam(value = "lstCustManagerName",defaultValue = "") String lstCustManagerName,
                              @RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,
                              @RequestParam(defaultValue = "3") Integer pageSize, Model model){
        IPage<CstLost> cstLostIPage = cstLostService.selectCstLost(lstCustName,lstCustManagerName,pageIndex,pageSize);
        model.addAttribute("rolePage",cstLostIPage);
        model.addAttribute("lstCustName",lstCustName);
        model.addAttribute("lstCustManagerName",lstCustManagerName);
        return "/lost/list";
    }

    /**
     * 修改
     * @param lstId 客户编号
     * @param model 传值
     * @return 跳转到修改页面
     */
    @RequestMapping("/lostc/edit")
    public String cstLostEdit(String lstId,Model model){
        CstLost lost = cstLostService.selectCstLostUpdate(lstId);
        String[] name = lost.getLstCustManagerName().split(",");
        model.addAttribute("losts",lost);
        model.addAttribute("lstCustManagerName1",name[0]);
        model.addAttribute("lstCustManagerName2",name[1]);
        return "/lost/edit";
    }

    /**
     * 修改
     * @param cstLost 客户实体类
     * @return 修改成功跳转到客户流失列表
     */
    @RequestMapping("/lost/save")
    public String cstLostSave(CstLost cstLost){
        cstLostService.toUpdateCstLost(cstLost);
        return "redirect:/lost/list";
    }
}
